import { Entity, Column, Index } from 'typeorm';
import { BaseEntity } from '../common/base/base.entity';

@Entity('system_logs')
@Index('idx_user_time', ['userId', 'createdAt'])
export class SystemLog extends BaseEntity {
  @Column({
    type: 'bigint',
    nullable: true,
    comment: '操作用户ID',
  })
  userId?: string;

  @Column({
    type: 'varchar',
    length: 50,
    nullable: true,
    comment: '操作用户名',
  })
  username?: string;

  @Column({
    type: 'varchar',
    length: 50,
    nullable: true,
    comment: '模块',
  })
  module?: string;

  @Column({
    type: 'varchar',
    length: 50,
    nullable: true,
    comment: '操作',
  })
  action?: string;

  @Column({
    type: 'text',
    nullable: true,
    comment: '操作描述',
  })
  description?: string;

  @Column({
    type: 'varchar',
    length: 10,
    nullable: true,
    comment: 'HTTP方法',
  })
  method?: string;

  @Column({
    type: 'varchar',
    length: 500,
    nullable: true,
    comment: '请求URL',
  })
  url?: string;

  @Column({
    type: 'json',
    nullable: true,
    comment: '请求参数',
  })
  params?: any;

  @Column({
    type: 'int',
    nullable: true,
    comment: 'HTTP状态码',
  })
  statusCode?: number;

  @Column({
    type: 'varchar',
    length: 50,
    nullable: true,
    comment: '操作IP',
  })
  ip?: string;

  @Column({
    type: 'int',
    nullable: true,
    comment: '执行时长(ms)',
  })
  duration?: number;
}
